<?php

namespace app\common\dao;

use ShidianUtil\Thinkphp\Dao\DaoTrait;
use app\common\model\Setting;

/**
 * SettingDao 数据访问对象
 * Class SettingDao
 * @package app\admin\dao
 * @method Setting findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method Setting insertActive(array $params, array $allow_field = [])
 * @method Setting updateActive(Setting $model, array $params, array $allow_field = [])
 * @method Setting findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method Setting updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(Setting $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class SettingDao
{
    use DaoTrait;

    /**
     * @var Setting
     */
    private $baseModel;

    /**
     * SettingDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = Setting::class;
    }

    public function findByKey($key):?Setting{
        return Setting::where('key', $key)->find();
    }

    public function getValueByKey($key, $default = null){
        return Setting::where('key', $key)->value('value', $default);
    }
}
